<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
<title>个人贷款试算器</title>
<link href="base.css" rel="stylesheet" type="text/css">
<link href="tool.css" rel="stylesheet" type="text/css">
<link href="art.default.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="base.js"></script>
<script type="text/javascript" src="artDialog.basic.js"></script>
<script type="text/javascript">

function sendrate2() {

	var original = $id('original');
	var yearSpan = $id('yearSpan');
	var active = $id('active');

    if (!checkFormPlus(original, "贷款总额")){return false;}
    if (!checkFormInt(yearSpan, "按揭年数")){return false;}
    if (!checkFormPlus(active, "贷款年利率")){return false;}

    //从表单中取值

    var original = original.value; //贷款总额
    var active = active.value; //贷款利息
    var yearSpan = yearSpan.value; //年数

    //alert(yearSpan);

    var timeSpan = parseFloat(yearSpan) * 12;
    active = active * 10 / 12;

    //计算贷款利息、本息合计

    var result = new Array();

    if (inputSelect.value == "1") {
        result = estateBorrow(original, active, timeSpan);//贷款利息、利息税额、实得利息、本息合计封在返回的数组中
        //将贷款利息本息合计显示
        $id('monthBack').value = result[0]; //显示贷款利息
        $id('totalBack').value = result[1]; //显示本息合计
        //formObj.monthInterest.value=result[2];        //显示贷款利息
        $id('totalInterest').value = result[3]; //显示本息合计
        $id("tr_debj").style.display = 'none';
        $id("tr_debx").style.display = '';

    }else {

        var result = estateBorrow1(original, active, timeSpan);
		
        $id('totalInterest').value = result[0]; //显示贷款利息
        $id('totalBack').value = result[1]; //显示本息合计
        $id('monthBackDEBJ').value = result[2];//显示每月还款额
        $id("tr_debx").style.display = 'none';
        $id("tr_debj").style.display = '';
		$id('monthBackDEBJ').style.height = (timeSpan * 23)+'px';

    }

}



function estateBorrow(original,active,timeSpan){

    var monthBack= (original*active*0.001*Math.pow((1+parseFloat(active*0.001)),parseFloat(timeSpan))/(Math.pow((1+parseFloat(active*0.001)),parseFloat(timeSpan))-1)).format(2);
    var totalBack= (monthBack*timeSpan).format(2);
    var totalInterest= (totalBack-original).format(2);
    var monthInterest= (totalInterest/timeSpan).format(2);
	
	var objArray=new Array();
	objArray[0]=monthBack;
	objArray[1]=totalBack;
	objArray[2]=monthInterest;
	objArray[3]=totalInterest;        
	return objArray;
}

function estateBorrow1(original,active,timeSpan){

    active = active*0.001;
    var monthOriginal = original / timeSpan;
    var timeSpan1=parseInt(timeSpan);
    var interestTotal=0;    
    var backMonth = "";
    for(i=1;i<timeSpan1+1;i++){
        interestM=(original-original*(i-1)/timeSpan1)*active;
        backMonth += i + "月:" + (monthOriginal + interestM).toFixed(2) + "元\n";
        interestTotal= (parseFloat(interestTotal)+parseFloat(interestM)).format(2);          
    }
    var monthBack=original*active*Math.pow((1+parseFloat(active)),parseFloat(timeSpan))/(Math.pow((1+parseFloat(active)),parseFloat(timeSpan))-1);
    var moneyTotal=parseFloat(original)+parseFloat(interestTotal);
	var objArray=new Array();
	objArray[0]=interestTotal.format(2);
	objArray[1]=moneyTotal.format(2);
	objArray[2] = backMonth;
	return objArray;
}

function frmReset(frm){
	frm.reset();	
	$id("tr_debj").style.display = 'none';
    $id("tr_debx").style.display = '';
}

</script>
</head>
<body>
<div class="container" id="container">
  <form action="" method="post" onSubmit="return false;">
  <div class="title">
    <h2>个人贷款试算器</h2>
    <div class="bg"></div>
  </div>
  <div class="content">
   	
      <div class="warm_tip">
      	<p>个人贷款试算器可以帮助您计算贷款时各种还款方式下的各项数据。
        </p>
      </div> 
      
      <ul class="form_items">
        <li>
          <label>贷款种类:</label>
          <span>
          <select name="borrowtype" id="borrowtype">
            <option value="1" selected="selected">个人住房贷款</option>
            <option value="2">个人旅游贷款</option>
            <option value="3">个人综合消费贷款</option>
            <option value="4">个人短期信用贷款</option>
            <option value="5">个人小额抵押贷款</option>
            <option value="6">个人汽车贷款</option>
            <option value="7">助学贷款</option>
            <option value="8">个人留学贷款</option>
            <option value="9">大额耐用消费品贷款</option>
          </select>
          </span> </li>
        <li>
          <label>贷款总额:</label>
          <span>
          <input value="" type="text" name="original" id="original">
          元</span> </li>
        <li>
          <label>按揭年数:</label>
          <span>
          <input value="" type="text" id="yearSpan" name="yearSpan">
          年</span> </li>
        <li>
          <label>还款方式:</label>
          <span>
          <select name="inputSelect" id="inputSelect">
            <option value="1" selected="selected">等额本息还款</option>
            <option value="2">等额本金还款</option>
          </select>
          </span> </li>
        <li>
          <label>贷款年利率:</label>
          <span>
          <input value="" type="text"  name="active" id="active"> %
          </span> </li>
      </ul>
      <div class="button_bar">
        <input type="button" onClick="sendrate2();" value="开始计算" class="submit"/>
        <input type="button" id="hqResetBtn" value="重新计算" class="reset" onClick="frmReset(this.form)"/>
      </div>
    
  </div>
  <div class="title">
    <h2>计算结果</h2>
    <div class="bg"></div>
  </div>
  <div class="content">
    <ul class="form_items">
      
      <li>
        <label>支付利息：</label>
        <span>
        <input type="text" value="" name="totalInterest" id="totalInterest" readonly="readonly" disabled="true" role="disabled"/>
        元 </span> </li>
      <li>
        <label>还款总额：</label>
        <span>
        <input type="text" class="txt1" value="" name="totalBack" id="totalBack" readonly="readonly" disabled="true" role="disabled"/>
        元 </span> </li>
      <li id="tr_debx">
        <label>月均还款：</label>
        <span>
        <input type="text" value="" name="monthBack" id="monthBack" readonly="readonly" disabled="true" role="disabled"/>
        元 </span> </li>
      <li id="tr_debj" style="display:none">
        <label>月还金额：</label>
        <span>
        <textarea name="monthBackDEBJ" id="monthBackDEBJ"  readonly="readonly" disabled="true" role="disabled"></textarea>
         </span> </li>  
       
    </ul>
  </div>
  </form>
</div>
</body>
</html>
